﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Supermarket.Bll;

namespace Supermarket.Web.CashierPages
{
    public partial class Products : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        
        }

        protected void LinkButtonAdd_Click(object sender, EventArgs e)
        {
            LinkButtonAdd.Visible = false;
            PanelAddProduct.Visible = true;
        }

        protected void ButtonCancel_Click(object sender, EventArgs e)
        {
            PanelAddProduct.Visible = false;
            LinkButtonAdd.Visible = true;
        }

        protected void fvProduct_ItemInserting(object sender, FormViewInsertEventArgs e)
        {
            TextBox tbProductName = (TextBox)fvProduct.FindControl("TextBoxProductName");
            TextBox tbProductPrice = (TextBox)fvProduct.FindControl("TextBoxProductPrice");
            DropDownList ddlCompanyName = (DropDownList)fvProduct.FindControl("ddlCompanyName");
            DropDownList ddlCategoryName = (DropDownList)fvProduct.FindControl("ddlCategoryName");
            DropDownList ddlMeasureCode = (DropDownList)fvProduct.FindControl("ddlMeasureCode");

            string productName = tbProductName.Text;
            decimal productPrice = decimal.Parse(tbProductPrice.Text);
            int productCompanyId = int.Parse(ddlCompanyName.SelectedValue);
            int productCategoryId = int.Parse(ddlCategoryName.SelectedValue);
            int productMeasureId = int.Parse(ddlMeasureCode.SelectedValue);

            ProductManager.CreateProduct(productName, productPrice, productCompanyId, productCategoryId, productMeasureId);

            PanelAddProduct.Visible = false;
            LinkButtonAdd.Visible = true;
        }        
    }
}